home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1122 / 1122.xpi / chrome / tabmixplus.jar / content / tabmixplus / pref / pref-appearance.xml < prev    next >
Extensible Markup Language  |  2009-09-19  |  12KB  |  288 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE bindings [
  4. <!ENTITY % dialogDTD SYSTEM "chrome://tabmixplus/locale/pref-tabmix.dtd" >
  5. %dialogDTD;
  6. <!ENTITY % appearanceDTD SYSTEM "chrome://tabmixplus/locale/pref-appearance.dtd" >
  7. %appearanceDTD;
  8. ]>
  9.  
  10. <bindings id="tmp_tabStylesbindings"
  11.           xmlns="http://www.mozilla.org/xbl"
  12.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  13.           xmlns:xbl="http://www.mozilla.org/xbl">
  14.  
  15.   <binding id="tabstylepanel">
  16.     <content orient="vertical">
  17.       <xul:hbox align="center">
  18.         <xul:checkbox anonid="useThis" label="&useThis.label;: "
  19.                       oncommand="_updateUseThisState(this.checked);"/>
  20.         <xul:label style="font-weight: bold;"/>
  21.       </xul:hbox>
  22.       <xul:separator class="groove"/>
  23.       <xul:hbox align="center" style="height: 28px;" xbl:inherits="hidden=_hidebox">
  24.         <xul:checkbox anonid="italic" xbl:inherits="disabled" label="&italic.label;" style="font-style: italic;"/>
  25.         <xul:checkbox anonid="bold" xbl:inherits="disabled" label="&bold.label;" style="font-weight: bold;"/>
  26.         <xul:checkbox anonid="underline" class="tabStyles_underline" xbl:inherits="disabled" label="&underline.label;"/>
  27.       </xul:hbox>
  28.       <xul:hbox align="center" xbl:inherits="hidden=_hidebox">
  29.         <xul:checkbox anonid="text" xbl:inherits="disabled" label="&textcolor.label;:"
  30.                       oncommand="_setColorpicker(this.getAttribute('anonid'))"/>
  31.         <xul:spacer flex="1"/>
  32.         <xul:colorpicker anonid="textColor" palettename="standard" type="button" xbl:inherits="disabled=text-disabled"/>
  33.         <xul:label control="textOpacity" value="&opacity.label;[%]:" class="opacity" xbl:inherits="disabled=text-disabled"/>
  34.         <xul:textbox anonid="textOpacity" class="opacity" xbl:inherits="disabled=text-disabled"
  35.                      maxlength="3" size="1" type="number" min="0" max="100" colorcontrol="text"
  36.                      oncommand="_onOpacityChanged(this);"/>
  37.       </xul:hbox>
  38.       <xul:spacer flex="1" hidden="true" xbl:inherits="hidden=_hidespacer"/>
  39.       <xul:hbox align="center">
  40.         <xul:checkbox anonid="bg" xbl:inherits="disabled" label="&bgColor.label;:"
  41.                       oncommand="_setColorpicker(this.getAttribute('anonid'))"/>
  42.         <xul:spacer flex="1" />
  43.         <xul:colorpicker anonid="bgColor" palettename="standard" type="button" xbl:inherits="disabled=bg-disabled"/>
  44.         <xul:label control="bgOpacity" value="&opacity.label;[%]:" class="opacity" xbl:inherits="disabled=bg-disabled"/>
  45.         <xul:textbox anonid="bgOpacity" class="opacity" xbl:inherits="disabled=bg-disabled"
  46.                      maxlength="3" size="1" type="number" min="0" max="100" colorcontrol="bg"
  47.                      oncommand="_onOpacityChanged(this);"/>
  48.       </xul:hbox>
  49.       <xul:separator class="groove"/>
  50.       <xul:hbox align="center">
  51.         <xul:button label="&settings.default;" oncommand="_resetDefault();"/>
  52.       </xul:hbox>
  53.     </content>
  54.  
  55.     <implementation>
  56.       <constructor>
  57.         <![CDATA[
  58.           this.prefsSvc = TMPstyles.prefsSvc;
  59.           this._initUseThisPref = {prefvalue: this.prefsSvc.getBoolPref("extensions.tabmix." + this.id)};
  60.           this._initPrefValues = this.prefsSvc.getCharPref(this.prefName);
  61.  
  62.           var checked;
  63.           var tabmixOptionsWindow = this._tabmixOptions;
  64.           if (tabmixOptionsWindow) {
  65.             this._initUseThisPref.optionvalue = checked = this._tabmixOptionsItem.checked;
  66.             this.prefsSvc.setBoolPref("extensions.tabmix." + this.id, checked);
  67.             tabmixOptionsWindow.updateApplyData(this._tabmixOptionsItem, checked);
  68.           }
  69.           else
  70.             checked = this._initUseThisPref.prefvalue;
  71.  
  72.           if (this.id == "progressMeter")
  73.             this._getElementById("useThis").setAttribute("disabled" , true);
  74.  
  75.           this._getElementById("useThis").checked = checked;
  76.           this.disabled = !checked;
  77.  
  78.           this._getElementById("useThis").nextSibling.value = document.getElementById("_" + this.id).label;
  79.           // colorpicker need some time untile its ready
  80.           window.setTimeout( function(self) {self._getPrefs(self._initPrefValues);}, 0, this)
  81.         ]]>
  82.       </constructor>
  83.  
  84.       <field name="_initUseThisPref">null</field>
  85.       <field name="_initPrefValue">null</field>
  86.       <field name="prefsSvc">null</field>
  87.       <field name="_prefValues">null</field>
  88.  
  89.       <property name="prefName"
  90.                 onget="return 'extensions.tabmix.styles.' + this.id;"
  91.                 readonly="true"/>
  92.  
  93.       <field name="_tabmixOptionsItem">null</field>
  94.       <property name="_tabmixOptions" readonly="true">
  95.         <getter>
  96.           <![CDATA[
  97.             var win = window.opener;
  98.             this._tabmixOptionsItem = win.document.getElementById(this.id);
  99.             return win;
  100.           ]]>
  101.         </getter>
  102.       </property>
  103.  
  104.       <property name="disabled"
  105.         onget="return this.getAttribute('disabled');">
  106.         <setter>
  107.           <![CDATA[
  108.             if(val)
  109.               this.setAttribute("disabled", true);
  110.             else
  111.               this.removeAttribute("disabled");
  112.           ]]>
  113.         </setter>
  114.       </property>
  115.  
  116.       <method name="_getElementById">
  117.         <parameter name="aID"/>
  118.         <body><![CDATA[
  119.           return document.getAnonymousElementByAttribute(this, "anonid", aID);
  120.         ]]></body>
  121.       </method>
  122.  
  123.       <method name="_updateUseThisState">
  124.         <parameter name="aEnabled"/>
  125.         <body><![CDATA[
  126.           this.prefsSvc.setBoolPref("extensions.tabmix." + this.id, aEnabled);
  127.           var tabmixOptionsWindow = this._tabmixOptions;
  128.           if (tabmixOptionsWindow) {
  129.             this._tabmixOptionsItem.checked = aEnabled;
  130.             if (this.id == "progressMeter")
  131.               tabmixOptionsWindow.TM_Options.disabled("progressMeter");
  132.           }
  133.  
  134.           this.disabled = !aEnabled
  135.           this._setColorpicker("bg");
  136.           if ("text" in this._prefValues)
  137.             this._setColorpicker("text");
  138.         ]]></body>
  139.       </method>
  140.  
  141.       <method name="_resetDefault">
  142.         <parameter name="aResetOnlyStyle"/>
  143.         <body><![CDATA[
  144.           if (!aResetOnlyStyle && this.prefsSvc.prefHasUserValue("extensions.tabmix." + this.id)) {
  145.             var useThis = this._getElementById("useThis");
  146.             useThis.checked = !useThis.checked;
  147.             this._updateUseThisState(useThis.checked);
  148.             this._initUseThisPref.prefvalue = this._initUseThisPref.optionvalue = useThis.checked;
  149.           }
  150.  
  151.           var pref = this.prefName;
  152.           if (this.prefsSvc.prefHasUserValue(pref))
  153.             this.prefsSvc.clearUserPref(pref);
  154.           this._initPrefValues = this.prefsSvc.getCharPref(this.prefName);
  155.           this._getPrefs(this._initPrefValues);
  156.         ]]></body>
  157.       </method>
  158.  
  159.       <method name="_getPrefs">
  160.         <parameter name="aPrefString"/>
  161.         <body><![CDATA[
  162.           try {
  163.             this._prefValues = Components.utils.evalInSandbox("({" + aPrefString + "})",
  164.                                              new Components.utils.Sandbox("about:blank"));
  165.           }
  166.           catch (er) {
  167.             this._resetDefault(true);
  168.             return;
  169.           }
  170.  
  171.           for (var _id in this._prefValues) {
  172.              var item = this._getElementById(_id);
  173.              if (!item)
  174.                continue;
  175.              switch (item.localName) {
  176.                case "checkbox":
  177.                  item.checked = this._prefValues[_id];
  178.                  break;
  179.                case "colorpicker":
  180.                   // colorpicker use rgb hexadecimal format
  181.                   var rgbArray = this._prefValues[_id].replace(/rgba|rgb|\(|\)/g, "").split(",");
  182.                   var opacity = rgbArray.splice(3, 1);
  183.                   item.color = "#" + rgbArray.map(function(aInt){return parseInt(aInt).toString(16).replace(/^(.)$/, "0$1")}
  184.                                      ).join("").toUpperCase();
  185.                  var controlID = _id.replace("Color", "Opacity");
  186.                  this._getElementById(controlID).value = (opacity || 1 ) * 100;
  187.                  break;
  188.              }
  189.           }
  190.           if ("text" in this._prefValues) {
  191.             this._setColorpicker("text");
  192.             this._prefValues["textOpacity"] = 1;
  193.           }
  194.           this._setColorpicker("bg");
  195.           this._prefValues["bgOpacity"] = 1;
  196.         ]]></body>
  197.       </method>
  198.  
  199.       <method name="_savePrefs">
  200.         <body><![CDATA[
  201.           var prefString = [];
  202.           for (var _id in this._prefValues) {
  203.             var item = this._getElementById(_id);
  204.             switch (item.localName) {
  205.               case "checkbox":
  206.                 prefString.push(_id + ":" + item.checked);
  207.                 break;
  208.               case "colorpicker":
  209.                 prefString.push(_id + ":'" + item.color + "'");
  210.                 break;
  211.               case "textbox":
  212.                 prefString.push(_id + ":'" + item.value/100 + "'");
  213.                 break;
  214.             }
  215.           }
  216.           this.prefsSvc.setCharPref(this.prefName, prefString.join(","));
  217.         ]]></body>
  218.       </method>
  219.  
  220.       <method name="_ondialogcancel">
  221.         <body><![CDATA[
  222.           this.prefsSvc.setCharPref(this.prefName, this._initPrefValues);
  223.           this.prefsSvc.setBoolPref("extensions.tabmix." + this.id, this._initUseThisPref.prefvalue);
  224.           var tabmixOptionsWindow = this._tabmixOptions;
  225.           if (tabmixOptionsWindow) {
  226.             tabmixOptionsWindow.updateApplyData(this._tabmixOptionsItem, this._initUseThisPref.optionvalue);
  227.             if (this.id == "progressMeter")
  228.               tabmixOptionsWindow.TM_Options.disabled("progressMeter");
  229.           }
  230.         ]]></body>
  231.       </method>
  232.  
  233.       <method name="_setColorpicker">
  234.         <parameter name="aID"/>
  235.         <body><![CDATA[
  236.           var opacity;
  237.           var enabled = this.disabled ? false : this._getElementById(aID).checked;
  238.           if (enabled) {
  239.             this.removeAttribute(aID + "-disabled");
  240.             opacity = this._getElementById(aID + "Opacity").value;
  241.           }
  242.           else {
  243.             this.setAttribute(aID + "-disabled", true);
  244.             opacity = 20;
  245.           }
  246.           this._setOpacity(aID, opacity);
  247.         ]]></body>
  248.       </method>
  249.  
  250.       <method name="_onOpacityChanged">
  251.         <parameter name="aOpacityControl"/>
  252.         <body><![CDATA[
  253.           var colorcontrolID = aOpacityControl.getAttribute("colorcontrol");
  254.           this._setOpacity(colorcontrolID, aOpacityControl.value);
  255.         ]]></body>
  256.       </method>
  257.  
  258.       <method name="_setOpacity">
  259.         <parameter name="aID"/>
  260.         <parameter name="aValue"/>
  261.         <body><![CDATA[
  262.           var opacity = aValue < 20 ? .20 : aValue/100;
  263.           var colorpicker = this._getElementById(aID + "Color");
  264.           colorpicker.setAttribute("style", "opacity: " + opacity);
  265.         ]]></body>
  266.       </method>
  267.  
  268.     </implementation>
  269.     <handlers>
  270.       <handler event="command">
  271.         this._savePrefs();
  272.       </handler>
  273.       <handler event="change">
  274.         if (event.originalTarget.localName == "colorpicker")
  275.           this._savePrefs();
  276.       </handler>
  277.       <handler event="input">
  278.         var item = event.originalTarget.parentNode.parentNode;
  279.         if (item.localName == "textbox") {
  280.           this._onOpacityChanged(item);
  281.           this._savePrefs();
  282.         }
  283.       </handler>
  284.     </handlers>
  285.   </binding>
  286.  
  287. </bindings>
  288.